import Vue from "vue";
import VueRouter from "vue-router";
import Layout from '@/layout'


Vue.use(VueRouter);

/**
 * hidden:菜单显隐
 * meta中activeMenu：用户隐藏菜单时，外层菜单仍处于选中状态
 */
export const permissionsRoute = [
    {
        path: '/sampleManage',
        component: Layout,
        redirect: '/sampleManage/sample',
        meta: { title: '样品管理', img: 'YPGL' },
        children: [
            {
                path: 'sample',
                component: () => import('@/views/sampleManage/sample'),
                name: 'Sample',
                meta: { title: '样品查询' }
            },
            {
                path: 'returnSample',
                component: () => import('@/views/sampleManage/returnSample'),
                name: 'ReturnSample',
                meta: { title: '返样管理' }
            },
            {
                path: 'outStore',
                component: () => import('@/views/sampleManage/outStore'),
                name: 'OutStore',
                meta: { title: '出库记录' }
            },
            {
                path: 'inStore',
                component: () => import('@/views/sampleManage/inStore'),
                name: 'InStore',
                meta: { title: '入库记录' }
            },
        ]
    },
    {
        path: '/checkManage',
        component: Layout,
        redirect: '/checkManage/start',
        meta: { title: '检测管理', img: 'JCGL' },
        children: [
            {
                path: 'start',
                component: () => import('@/views/checkManage/start'),
                name: 'Start',
                meta: { title: '开始检测' }
            },
            {
                path: 'static',
                component: () => import('@/views/checkManage/static'),
                name: 'Static',
                meta: { title: '静置查询' }
            },
            {
                path: 'experiment',
                component: () => import('@/views/checkManage/experiment'),
                name: 'Experiment',
                meta: { title: '试验管理' }
            },
            {
                path: 'remnants',
                component: () => import('@/views/checkManage/remnants'),
                name: 'Remnants',
                meta: { title: '残样管理' }
            },
        ]
    },


]

export const allRouter = [
    {
        path: '/',
        redirect: '/login',// 当访问根路径时重定向到登录页
        hidden: true
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('@/views/login/login'),
        hidden: true
    },
    ...permissionsRoute
]

const router = new VueRouter({
    mode: 'hash', // 使用 hash 模式
    routes: allRouter
});
// router.beforeEach((to, from, next) => {
//     let isAuthenticated = true    //判断是否登录
//     if (to.path === '/login' && isAuthenticated) {
//         next('/module'); // 如果用户已登录并试图访问登录页，则重定向到主页
//     }
//     else if (to.path !== '/login' && !isAuthenticated) {
//         next('/login'); // 如果需要认证但用户未登录，则重定向到登录页
//     }
//     else {
//         next(); // 
//     }
// });


export default router;